<%@ page import="moudle.Student" %>
<%@ page import="java.util.List" %>
<%@ page import="service.impl.StudentImplService" %>
<%--
  Created by IntelliJ IDEA.
  User: 34806
  Date: 2025/5/7
  Time: 10:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>学生信息列表展示</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://cdn.staticfile.net/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.net/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.net/popper.js/1.15.0/umd/popper.min.js"></script>
    <script src="https://cdn.staticfile.net/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>
<%
    //    List<Student> data = (List<Student>) request.getAttribute("data");
    /**
     *     作用域问题：在 JSP 中，
     *     request.getAttribute("data") 获取数据，
     *     request 作用域仅在一次请求 - 响应过程中有效。
     *     点击下一页是新请求，之前 request 作用域里的数据不会自动带到新请求中。
     *     若没有重新设置 data 到新 request 作用域，就获取不到。
     */
    StudentImplService studentImplService1 = new StudentImplService();
    List<Student> data = studentImplService1.getAllService();

//    1.计算有多少条数据
    int totalCount = data.size();
//    2.设置每一页有几条数据
    int pageSize = 3;
//    3.计算有多少页
    int pageCount = (int) (Math.ceil(totalCount * 1.0 / pageSize));
//    4.获取当前页
    int curPage = request.getParameter("curPage") == null ?
            1 : Integer.valueOf(request.getParameter("curPage"));
//    计算偏移值
    int offSet = (curPage - 1) * 3;
//    5.获取当前页的数据
    StudentImplService studentImplService = new StudentImplService();
    List<Student> students = studentImplService.fenYeService(offSet, pageSize);
%>
<%--你依然保持在线！--%>
<a href='/javawebstudy2025_war_exploded/logout'>退出</a>
<table class="table">
    <thead class="thead-dark">
    <tr>
        <th>学号</th>
        <th>姓名</th>
        <th>性别</th>
        <th>年龄</th>
        <th>操作1</th>
        <th>操作2</th>
    </tr>
    </thead>
    <tbody>
    <%
        for (int i = 0; i < students.size(); i++) {
    %>
    <tr>
        <td>
            <%=students.get(i).getId()%>
        </td>
        <td>
            <%=students.get(i).getName()%>
        </td>
        <td>
            <%=students.get(i).getSex()%>
        </td>
        <td>
            <%=students.get(i).getAge()%>
        </td>
        <td>
            <a href="/javawebstudy2025_war_exploded/Do?method=delDo&id=<%=students.get(i).getId()%>"
               onclick="if(confirm('确认删除吗？')) return true;return false;">删除</a>
        </td>
        <td>
            <a href="/javawebstudy2025_war_exploded/Do?method=getOneDo&id=<%=students.get(i).getId()%>">更新</a>
        </td>
    </tr>
    <%
        }

    %>
    <%
        if (curPage == 1) {

    %>
    <tr>
        <td>首页</td>
        <td>上一页</td>
        <td><a href="ShowList1.jsp?curPage=<%=curPage+1%>">下一页</a></td>
        <td><a href="ShowList1.jsp?curPage=<%=pageCount%>">尾页</a></td>
    </tr>
    <%
    } else if (curPage == pageCount) {
    %>
    <tr>
        <td><a href="ShowList1.jsp?curPage=1">首页</a></td>
        <td><a href="ShowList1.jsp?curPage=<%=curPage-1%>">上一页</a></td>
        <td>下一页</td>
        <td>尾页</td>
    </tr>
    <%
    } else {
    %>
    <tr>
        <td><a href="ShowList1.jsp?curPage=1">首页</a></td>
        <td><a href="ShowList1.jsp?curPage=<%=curPage-1%>">上一页</a></td>
        <td><a href="ShowList1.jsp?curPage=<%=curPage+1%>">下一页</a></td>
        <td><a href="ShowList1.jsp?curPage=<%=pageCount%>">尾页</a></td>
    </tr>
    <%
        }
    %>
    </tbody>
</table>

<button style='padding: 10px 20px;display: block; margin: 0 auto;'>
    <a href="/javawebstudy2025_war_exploded/add.html">添加</a>
</button>

</body>
</html>
